package com.budwk.app.sqfw.controllers.admin;

import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.hutool.core.util.ObjectUtil;
import com.budwk.app.sqfw.models.Sqfw_cenSusPaper;
import com.budwk.app.sqfw.services.SqfwPeopleInfoForAdminService;
import com.budwk.starter.common.openapi.annotation.ApiDefinition;
import com.budwk.starter.common.openapi.annotation.ApiFormParams;
import com.budwk.starter.common.openapi.annotation.ApiOperation;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.compress.utils.Lists;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

/**
 * App辖区人员信息
 *
 * @author zhangp
 * @date 2024/1/9 11:38
 * @Version1.0
 */
@IocBean
@At("/platform/sqfw/peopleInfo/app")
@ApiDefinition(tag = "App辖区人员信息")
@Slf4j
public class SqfwPeopleInfoForAppController {

    @Inject
    private SqfwPeopleInfoForAdminService sqfwPeopleInfoForAdminService;

    /**
     * 人员信息列表查询
     */
    @At("/getPeopleInfoList")
    @Ok("json")
    @GET
    @ApiOperation(name = "人员信息列表查询")
    @SLog(tag = "人员信息列表查询", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> getPeopleInfoList(@Param("queryParam") String queryParam, @Param("selectParam") String selectParam, @Param("pageSize") Integer pageSize, @Param("pageNo") Integer pageNo) {
        return Result.data(sqfwPeopleInfoForAdminService.getPeopleInfoList(queryParam, selectParam,pageSize,pageNo));
    }

    /**
     * 通过条件获取数据下载excel
     * @param queryParam
     * @param selectParam
     * @param fileIndex
     * @return
     */
    @At("/generatePeopleInfoExcelForAppByCond")
    @Ok("json")
    @POST
    @ApiOperation(name = "根据条件下载excel")
    @ApiFormParams(
            implementation = Sqfw_cenSusPaper.class
    )
    @SLog(tag = "根据条件下载excel", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> generatePeopleInfoExcelForAppByCond(@Param("queryParam") String queryParam, @Param("selectParam") String selectParam,@Param("fileIndex") Integer fileIndex,@Param("startTime") String startTime,@Param("endTime") String endTime) {
        if (ObjectUtil.isEmpty(fileIndex)) {
            return Result.error("下载类型不能为空！");
        }
        String excelUrl = sqfwPeopleInfoForAdminService.generatePeopleInfoExcelForAppByCond(queryParam,selectParam,fileIndex,null,startTime,endTime, Lists.newArrayList());
        if (null == excelUrl) {
            return Result.error("无匹配记录！");
        }
        return Result.data(excelUrl);
    }

    /**
     * App 检测数据
     * @param queryParam
     * @param selectParam
     * @return
     */
    @At("/checkParamFromHouseInfoForApp")
    @Ok("json")
    @POST
    @ApiOperation(name = "检测excel数据")
    @SLog(tag = "检测excel数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> checkParamFromHouseInfoForApp(@Param("queryParam") String queryParam, @Param("selectParam") String selectParam,@Param("startTime") String startTime,@Param("endTime") String endTime,@Param("fileIndex") Integer fileIndex) {
        return Result.data(sqfwPeopleInfoForAdminService.checkParamFromHouseInfoForApp(queryParam,selectParam,startTime,endTime,fileIndex));
    }

    @At("/getHouseSurveyInfoListByAddress")
    @Ok("json")
    @POST
    @ApiOperation(name = "根据详细地址查询入户调查信息")
    @SLog(tag = "根据详细地址查询入户调查信息", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> getHouseSurveyInfoListByAddress(@Param("unitId") String unitId, @Param("a15") String a15) {
        return Result.success(sqfwPeopleInfoForAdminService.getHouseSurveyInfoListByAddress(unitId, a15));
    }

    /**
     * 勾选下载Excel
     *
     * @param fileIndex 文件索引key
     */
    @At("/generatePeopleInfoTemplateDownloadForApp")
    @Ok("json")
    @POST
    @ApiOperation(name = "住户信息模板下载")
    @ApiFormParams(
            implementation = Sqfw_cenSusPaper.class
    )
    @SLog(tag = "住户信息模板下载", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> generatePeopleInfoTemplateDownloadForApp(@Param("fileIndex") Integer fileIndex) {
        if (ObjectUtil.isEmpty(fileIndex)) {
            return Result.error("下载类型不能为空！");
        }
        String excelUrl = sqfwPeopleInfoForAdminService.generatePeopleInfoTemplateDownload(fileIndex);
        if (null == excelUrl) {
            return Result.error("无匹配记录！");
        }
        return Result.data(excelUrl);
    }



}
